package com.arnold.www.singleton;

import sun.awt.windows.ThemeReader;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName Singletion_test
 * @Description: 单例测试
 * @Author Arnold
 * @Date 2020/4/11
 * @Version V2.0
 **/
public class Singletion_test {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(20);
        for (int i=0;i<10;i++){
            //饿汉式多线程演示（不存在线程不安全的问题出现）
//            executorService.submit(new Runnable() {
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"/t"+Singleton_hungry.getInstance());
//                }
//            });
            //懒汉式多线程演示（线程安全问题出现）
//            executorService.submit(new Runnable() {
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"/t"+Singleton_lazyLoading.getInstance());
//                }
//            });
            //懒汉式多线程演示（synchronized重度锁机制）
//            executorService.submit(new Runnable() {
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"/t"+Singleton_lazyLoading_synchronized.getInstance());
//                }
//            });
            //懒汉式多线程演示（synchronized重度锁机制）
            executorService.submit(new Runnable() {
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"/t"+Singleton_lazyLoading_doubleCheckLock.getInstance());
                }
            });
        }
        executorService.shutdown();
    }
}